<?php namespace Cms\Controller;

use Hdphp\Controller\Controller;

class MenuController extends Controller
{
  //GET /photo 索引
  public function index()
  {
    $menu = Api('Menu/getLevelMenu');
    $this->assign('menu', $menu);
    $this->display();
  }

  //GET /photo/create 创建界面
  public function create()
  {
    $menu = Api('Menu/getLevelMenu');
    View::with('menu', $menu)->make();
  }

  //POST /photo 保存新增数据
  public function store()
  {
    
    if (Api('Menu/store'))
    {
      $json = array(
        'code'    => 0,
        'message' => '创建成功'
        );
    }
    else
    {
      $json = array(
        'code'    => 1,
        'message' => Api('Menu/getError')
        );
    }
    $this->ajax($json);
  }

  //GET /photo/{photo} 显示文章
  public function show()
  {
echo 33;
  }

  //GET /photo/{photo}/edit 更新界面
  public function edit($id)
  {
    View::with('menu', Api('Menu/getLevelMenu', array(Q('id'))));
    View::with('field', Api('Menu/get', array($id)));
    View::make();
  }

  //PUT /photo/{photo} 更新数据
  public function update($id) 
  {
    if (Api('Menu/update',array($id)))
    {
      $json = array(
        'code'    => 0,
        'message' => '更新成功'
        );
    }
    else
    {
      $json = array(
        'code'    => 1,
        'message' => Api('Menu/getError')
        );
    }
    $this->ajax($json);
  }

  //DELETE /photo/{photo} 删除
  public function destroy()
  {
    if (Api('Menu/destroy', array($_GET['id'])))
    {
      $json = array(
        'code'    => 0,
        'message' => '删除成功'
        );
    }
    else
    {
      $json = array(
        'code'    => 1,
        'message' => Api('Menu/getError')
        );
    }
    $this->ajax($json);
  }
}